package cn.zhangzhan.word.api.controller.template;

import cn.zhangzhan.common.annotation.Log;
import cn.zhangzhan.common.core.controller.BaseController;
import cn.zhangzhan.common.core.domain.AjaxResult;
import cn.zhangzhan.common.core.page.TableDataInfo;
import cn.zhangzhan.common.enums.BusinessType;
import cn.zhangzhan.common.utils.poi.ExcelUtil;
import cn.zhangzhan.word.model.domain.template.AreaCode;
import cn.zhangzhan.word.service.service.AreaCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 蚂蚁金服地区码Controller
 *
 * @author zhangzhan
 * @date 2024-10-30
 */
@Api("蚂蚁金服地区码控制器")
@RestController
@RequestMapping("/tmp/area/code")
public class AreaCodeController extends BaseController
{
    @Autowired
    private AreaCodeService areaCodeService;

    /**
     * 查询蚂蚁金服地区码列表
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "查询蚂蚁金服地区码列表",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:list')")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public TableDataInfo list(AreaCode areaCode)
    {
        startPage();
        List<AreaCode> list = areaCodeService.selectAreaCodeList(areaCode);
        return getDataTable(list);
    }

    /**
     * 导出蚂蚁金服地区码列表
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "导出蚂蚁金服地区码列表",httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:export')")
    @Log(title = "蚂蚁金服地区码", businessType = BusinessType.EXPORT)
    @RequestMapping(value = "/export",method = RequestMethod.POST)
    public void export(HttpServletResponse response, AreaCode areaCode)
    {
        List<AreaCode> list = areaCodeService.selectAreaCodeList(areaCode);
        ExcelUtil<AreaCode> util = new ExcelUtil<AreaCode>(AreaCode.class);
        util.exportExcel(response, list, "蚂蚁金服地区码数据");
    }

    /**
     * 获取蚂蚁金服地区码详细信息
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "获取蚂蚁金服地区码详细信息",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:query')")
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(areaCodeService.selectAreaCodeById(id));
    }

    /**
     * 新增蚂蚁金服地区码
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "新增蚂蚁金服地区码",httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:add')")
    @Log(title = "蚂蚁金服地区码", businessType = BusinessType.INSERT)
    @RequestMapping(method = RequestMethod.POST)
    public AjaxResult add(@RequestBody AreaCode areaCode)
    {
        return toAjax(areaCodeService.insertAreaCode(areaCode));
    }

    /**
     * 修改蚂蚁金服地区码
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "修改蚂蚁金服地区码",httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:edit')")
    @Log(title = "蚂蚁金服地区码", businessType = BusinessType.UPDATE)
    @RequestMapping(method = RequestMethod.PUT)
    public AjaxResult edit(@RequestBody AreaCode areaCode)
    {
        return toAjax(areaCodeService.updateAreaCode(areaCode));
    }

    /**
     * 删除蚂蚁金服地区码
     * @author zhangzhan
     * @date 2024-10-30
     */
    @ApiOperation(value = "删除蚂蚁金服地区码",httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('tmp:areaCode:remove')")
    @Log(title = "蚂蚁金服地区码", businessType = BusinessType.DELETE)
    @RequestMapping(value = "/{ids}", method = RequestMethod.DELETE)
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(areaCodeService.deleteAreaCodeByIds(ids));
    }
}
